package com.study.demo_file_upload.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName: MyException
 * @Description:
 * @author: WS
 * @date 2020/12/11
 * @Version: 1.0
 **/
@ControllerAdvice
public class MyException {
    //    @ExceptionHandler(MaxUploadSizeExceededException.class)
//    public void myException(MaxUploadSizeExceededException e, HttpServletResponse response) throws IOException {
//        response.setContentType("text/html;charset=utf-8");
//        PrintWriter writer = response.getWriter();
//        writer.print("文件大小超出限制");
//        writer.flush();
//        writer.close();
//    }
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public ModelAndView myException(MaxUploadSizeExceededException e) {
        ModelAndView myerror = new ModelAndView("myerror");
        myerror.addObject("error","文件上传大小超出限制");
        return myerror;
    }
}
